﻿/*
 * 
 *     This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 * 
 * BoogieMan - 2009
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MpqReader;

namespace WoW.DataManager
{
    public class MPQManager
    {
        private List <MpqArchive> MPQArchives;

        public MPQManager()
        {
            MPQArchives = new List<MpqArchive>();

            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\patch-2.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\patch.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\lichking.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\expansion.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\common-2.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\common.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\enUS\\patch-enUS-2.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\enUS\\patch-enUS.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\enUS\\lichking-locale-enUS.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\enUS\\expansion-locale-enUS.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\enUS\\locale-enUS.MPQ")));
            MPQArchives.Add(new MpqArchive(String.Format("{0}{1}" , DataManager.MPQPath, "Data\\enUS\\base-enUS.MPQ")));
        }

        public MpqStream OpenFile(string FileName)
        {
            foreach (MpqArchive archive in MPQArchives)
            {
                if (archive.FileExists(FileName))
                {
                    return archive.OpenFile(FileName);
                }
            }
            return null;
        }
    }
}
